﻿using Demo.OrderService.Entities;
using Demo.OrderService.Repositorys;
using Demo.OrderService.Services.Dtos;
using Volo.Abp.Application.Services;
using Mapster;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace Demo.OrderService.Services
{
    /// <summary>
    /// 订单模块服务层
    /// </summary>
    [Dependency(ServiceLifetime.Singleton)]
    public class OrderService : CrudAppService<ShopOrder, ShopOrderDto, Guid>, IOrderService
    {

        private readonly IOrderRepoistory orderRepoistory;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="repository"></param>
        public OrderService(IOrderRepoistory repository) : base(repository)
        {
            orderRepoistory = repository;
        }

        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="orderDto"></param>
        /// <returns></returns>
        public async Task<ShopOrder> CreateOrderAsync(ShopOrderDto orderDto)
        {
            try
            {

                ShopOrder order = orderDto.Adapt<ShopOrder>();

                order.OrderNum = "1231231";
                order.CreateTime = DateTime.Now;
                order.PayOrderNum = "12312312312";
                order.OrderQuantity = 10;

                var shopOrder = await orderRepoistory.InsertAsync(order);

                return shopOrder;
            }
            catch (Exception e)
            {

                throw;
            }

        }
    }
}
